﻿using System;
using System.Collections.Generic;
using System.Linq;
using DataStore.Domain;
using NHibernate;
using NHibernate.Linq;

namespace DataStore.Repositories
{
    public class PropertiesRepository : IRepository<Domain.Properties>
    {
        readonly UnitOfWork _unitOfWork;

        /// <summary>
        /// Initializes a new instance of the <see cref="PropertiesRepository"/> class.
        /// </summary>
        /// <param name="unitOfWork">The unit of work.</param>
        public PropertiesRepository(UnitOfWork unitOfWork)
        {
            _unitOfWork = unitOfWork;
            
        }

        #region IPropertiesRepository Members


        /// <summary>
        /// Creates a new row in the data table for storing properties.
        /// </summary>
        public void Init()
        {

            ISession session = _unitOfWork.Session;
            session.Save(new Domain.Properties());
        }

        /// <summary>
        /// Gets or sets the current properties.
        /// </summary>
        /// <value>The current properties.</value>
        public Domain.Properties Current
        {
            get
            {
                ISession session = _unitOfWork.Session;
                return session.Linq<Domain.Properties>().FirstOrDefault();
                
            }
            set
            {
                ISession session = _unitOfWork.Session;
                session.Update(value);
            }
        }

        #endregion

        #region Implementation of IRepository<Properties>

        public Domain.Properties Get(object id)
        {
            ISession session = _unitOfWork.Session;
            return session.Linq<Domain.Properties>().FirstOrDefault();
        }

        public void Delete(Domain.Properties entity)
        {
            throw new NotImplementedException();
        }

        public void DeleteAll()
        {
            throw new NotImplementedException();
        }

        public void Save(Domain.Properties entity)
        {
            throw new NotImplementedException();
        }

        public Domain.Properties SaveOrUpdate(Domain.Properties entity)
        {
            throw new NotImplementedException();
        }

        public void Update(Domain.Properties entity)
        {
            throw new NotImplementedException();
        }

        public IEnumerable<Domain.Properties> All
        {
            get { throw new NotImplementedException(); }
        }

        public bool Exists(Domain.Properties entity)
        {
            throw new NotImplementedException();
        }

        public bool IsEmpty
        {
            get { throw new NotImplementedException(); }
        }

        public int Count(Domain.Properties entity)
        {
            throw new NotImplementedException();
        }

        public int CountAll()
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
